import PointerInteraction from 'ol/interaction/Pointer';
// 自定义拖拽交互
class Drag extends PointerInteraction {
    constructor() {
      super();
      this.coordinate = null; // 用于存储拖拽时的坐标
      this.feature = null; // 当前被拖拽的 Feature
    }
  
    handleDownEvent(evt) {
      const map = evt.map;
      const feature = map.forEachFeatureAtPixel(evt.pixel, (feat) => feat);
      if (feature) {
        this.coordinate = evt.coordinate;
        this.feature = feature;
        return true; // 表示捕获事件
      }
      return false;
    }
  
    handleDragEvent(evt) {
      if (this.feature) {
        const deltaX = evt.coordinate[0] - this.coordinate[0];
        const deltaY = evt.coordinate[1] - this.coordinate[1];
        this.coordinate = evt.coordinate;
        const geometry = this.feature.getGeometry();
        geometry.translate(deltaX, deltaY); // 更新几何体的坐标
      }
    }
  
    handleUpEvent() {
      this.coordinate = null;
      this.feature = null;
      return false; // 释放事件
    }
  }